package com.slj.springcloud.controller;

import com.slj.springcloud.model.response.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/pay/gateway")
@Slf4j
public class PayGatewayController {
    @Autowired
    private Environment environment;

    @GetMapping("/port")
    public Result<String> getPort(@RequestHeader Map<String, String> headers) {
        for (Map.Entry<String, String> entry : headers.entrySet()) {
            log.info("key={};value={}", entry.getKey(), entry.getValue());
        }
        String port = "";
        if (environment.containsProperty("server.port")) {
            port = environment.getProperty("server.port");
        }
        return Result.success(System.currentTimeMillis() + ":=" + port);
    }
}
